package test.link;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import learn.hibernate.service.ResourceServiceI;
import learn.hibernate.service.RoleServiceI;


    /**
    * @ClassName: Many2Many
    * @Description: 测试 role 和 resource 其中关系的维护由role负责
    * @author 宁少林
    * @date 2016年9月2日
    *
    */
public class Many2Many extends BaseServiceTest {

	@Autowired
	private ResourceServiceI resourceService;
	
	@Autowired
	private RoleServiceI roleService;
	
	@Test
	public void testSimpleSave(){
		resourceService.saveSimpleResource();
	}
	
	
	
	    /**
	    * @Title: testSaveResourceWithRole
	    * @Description: 只保存成功了resource.
	    * @param     
	    * @return void    
	    * @throws
	    */
	@Test
	public void  testSaveResourceWithRole() {
		resourceService.saveResourceWithRole();
	}
	
	
	    /**
	    * @Title: testDeleteResourceByHql
	    * @Description: 会抛出异常，因为维护关系在role中,使用hql模式，未处理关联关系.
	    * @param     
	    * @return void    
	    * @throws
	    */
	@Test
	public void  testDeleteResourceByHql() {
		resourceService.deleteResourceByHql();
	}
	
	
	    /**
	    * @Title: testSaveRoleWithResource
	    * @Description: 同时在3张表中保存了,role,resource,role_resource
	    * @param     
	    * @return void    
	    * @throws
	    */
	@Test
	public void testSaveRoleWithResource(){
		roleService.saveRoleWithResource();
	}
	
	   /**
	    * @Title: testSaveRoleWithResource
	    * @Description: 同时在3张表中保存了,role,resource,role_resource
	    * @param     
	    * @return void    
	    * @throws
	    */
	@Test
	public void testFindRerouceWithRole(){
		int id=3;
		resourceService.findResourceWithRole(id);
	}
	
	@Test
	public void testDeleteRoleByDao(){
		roleService.deleteRoleByDao(1);
	}
	
	@Test
	public void testDeleteRoleByHql(){
		roleService.deleteRoleByHql();
	}
	
	@Test
	public void testDeleteResourceByDaoDelete() {
		resourceService.deleteResourceByDaoDelete(2);
	}
	
	@Test
	public void testUpdateResourceWithRole() {
		resourceService.updateResourceWithRole(4);
	}
	
	@Test
	public void testUpdateRoleWithResource() {
		int id=1;
		roleService.updateRoleWithResource(id);
	}
}
